<?php
declare (strict_types=1);

namespace app\middleware;

use app\common\model\setting\TraceIDSetting;
use think\facade\Cache;
use think\facade\Log;

class Response
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        $response = $next($request);
        //取前1000个字符，写入日志
        Log::record(mb_substr($response->getContent(), 0, 1000, 'utf-8'), "response");
        TraceIDSetting::instance()->update();
        return $response;
    }
}
